<template>
  <div class="app-container">  
    <el-form :inline="true" :model="listQuery" class="demo-form-inline">
      <i class="el-icon-search btn-search" @click="handleShowSearch()"></i>
      <div class="btn-box">
         <a
        class="el-button el-button--success el-button--medium"
        href="http://123.57.59.222:8081/api/file/new_sign_template.xlsx"
        type="primary"
      >模版下载</a>
          <el-upload
           :action="UploadUrl()"
           :show-file-list="false"
          :on-success="handleImageSuccess"
          class="upload_image"
        >
           <el-button type="primary" v-show='roleName=="admin"'>导入</el-button>
        </el-upload>
     
      </div>
      <div  v-show="showbtns==true"  class="search-lf">
         <el-form-item label="战区">
        <el-select filterable
          v-model="listQuery.regionId"
        
          clearable
          @change="handleChangePro4($event)"
          placeholder="请选择"
        >
          <el-option
            v-for="item in regiosList"
            :key="item.id"
            :label="item.region"
            :value="item.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="省份">
        <el-select filterable v-model="listQuery.provinceId"  clearable placeholder="请选择">
          <el-option
            v-for="item in allProvinceList"
            :key="item.provinceId"
            :label="item.province"
            :value="item.provinceId"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="合同名称">
        <el-input v-model="listQuery.contractTitle" placeholder="合同名称"></el-input>
      </el-form-item>
      <el-form-item label="年">
        <el-date-picker
          v-model="listQuery.year"
         type="year"
            value-format="yyyy"
          
            placeholder="选择年"
        ></el-date-picker>
      </el-form-item>
        <el-form-item label="月份">
       <el-select filterable   v-model="listQuery.month">
         <el-option value='1'>1</el-option>
       
         <el-option value='2'>2</el-option>
         <el-option value='3'>3</el-option>
         <el-option value='4'>4</el-option>
         <el-option value='5'>5</el-option>
         <el-option value='6'>6</el-option>
         <el-option value='7'>7</el-option>
         <el-option value='8'>8</el-option>
         <el-option value='9'>9</el-option>
         <el-option value='10'>10</el-option>
         <el-option value='12'>12</el-option>
       </el-select>
      </el-form-item>
       <el-form-item>
        <el-button type="primary" plain @click="getList()">查询</el-button>
           
      </el-form-item>
      </div>
      
       
     
    </el-form>
    <el-table
      v-loading="listLoading" 
       border  height='650px'
      :data="list"
      fit
     
       highlight-current-row
      style="width: 100%"
    >
      <el-table-column align="center" width='60px' label="序号">
        <template slot-scope="scope">
          <span>{{scope.$index+1 }}</span>
        </template>
      </el-table-column>
   

      <el-table-column align="center" width="200px" label="客户名称">
        <template slot-scope="{row}">
          <span>{{ row.customerName }}</span>
        </template>
      </el-table-column>

      <el-table-column width='400px' align="center" label="合同标题">
        <template slot-scope="{row}">
          <span>{{ row.contractTitle }}</span>
        </template>
      </el-table-column>

      <el-table-column align="center" width='150px' label="合同总金额">
        <template slot-scope="{row}">
          <span>{{ row.contractAmount }}</span>
        </template>
      </el-table-column>

      <el-table-column align="center" label="业绩金额">
        <template slot-scope="{row}">
          <span>{{ row.financialAmount }}</span>
        </template>
      </el-table-column>
        <el-table-column align="center" label="负责人">
        <template slot-scope="{row}">
          <span>{{ row.chargeName }}</span>
        </template>
      </el-table-column>
        <el-table-column align="center" width='400px' label="合同编号">
        <template slot-scope="{row}">
          <span>{{ row.contractNo }}</span>
        </template>
      </el-table-column>
        <el-table-column align="center"  width='180px' label="产品品类">
        <template slot-scope="{row}">
          <span>{{ row.productTypeName }}</span>
        </template>
      </el-table-column>
        <el-table-column align="center" label="所属部门">
        <template slot-scope="{row}">
          <span>{{ row.salary }}</span>
        </template>
      </el-table-column>
        <el-table-column align="center" label="战区">
        <template slot-scope="{row}">
          <span>{{ row.regionName }}</span>
        </template>
      </el-table-column>
        <el-table-column align="center" label="业绩时间">
        <template slot-scope="{row}">
          <span>{{ row.performanceDate }}</span>
        </template>
      </el-table-column>
        <el-table-column align="center" label="月份">
        <template slot-scope="{row}">
          <span>{{ row.month }}</span>
        </template>
      </el-table-column>
        <el-table-column align="center" label="周">
        <template slot-scope="{row}">
          <span>{{ row.work }}</span>
        </template>
      </el-table-column>
        <el-table-column align="center" label="年份">
        <template slot-scope="{row}">
          <span>{{ row.year }}</span>
        </template>
      </el-table-column>
        <el-table-column align="center" label="财年">
        <template slot-scope="{row}">
          <span>{{ row.financialYear }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>=20"
      :total="total"
      :page.sync="listQuery.page"
      :limit.sync="listQuery.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {baseUrl2 }from '@/api/remote-search'
import { getNewSignList } from "@/api/base_data";
import Pagination from "@/components/Pagination";
import { regiosList } from "@/api/user";
import{getProvinces} from  "@/api/supplier";
import { RegionsProvince } from "@/api/region";
export default {
  name: "personelList",

  components: { Pagination },
  filters: {
    statusFilter(status) {
      const statusMap = {
        1: "男",
        0: "女",
      };
      return statusMap[status];
    },
  },
  data() {
    return {
      showbtns: false,
      roleName:sessionStorage.getItem('memberName'),
      regiosList: [], // 战区集合
      provinceList: [], //战区下面省份
      allProvinceList:[],//所有省份集合
      total: 0,

      listLoading: true,
      listQuery: {
        access_token: sessionStorage.getItem("token"),
        page: 1,
        provinceName: "",

        regionName: "",

        pageSize: 20,
      },
      list: [],
    };
  },
  created() {
    this.getList();
    this.getallProvinceList();
  },
  computed: {},
 methods: {
   getallProvinceList() {
      getProvinces().then((res) => {
        this.allProvinceList = res.data.data;
      });
    },
      handleClose(){
      this.editDisabled = false;
    },
    handleShowSearch() {
      this.showbtns = !this.showbtns;
    },
       UploadUrl(){
      return baseUrl2+'/api/file/import_new_sign'
    },
     handleImageSuccess(file) {
      if (file.code == 200) {
        this.$message.success(file.message);
        this.getList();
      } else {
        this.$message.error(file.message);
      }
    },
    handleChangePro4(id) {
       

      RegionsProvince(id).then((res) => {
        this.provinceList = res.data.data;
      });
    },

       getList() {
       this.editDisabled = false;
      regiosList().then((res) => {
        this.regiosList = res.data.data;
      });
      this.listLoading = true;
      getNewSignList(this.listQuery)
        .then((response) => {
          this.list = response.data.data.rows;
          this.total = response.data.data.total;
          this.listLoading = false;
        })
        .catch(() => {
          this.listLoading = false;
        });
    },
  },
};
</script>

<style scoped>
.edit-input {
  padding-right: 100px;
}
.cancel-btn {
  position: absolute;
  right: 15px;
  top: 10px;
}
</style>
